package com.yaorange.web.controller.nongjt;

import java.util.List;

import com.yaorange.framework.web.domain.server.Sys;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yaorange.common.annotation.Log;
import com.yaorange.common.core.controller.BaseController;
import com.yaorange.common.core.domain.AjaxResult;
import com.yaorange.common.enums.BusinessType;
import com.yaorange.nongjt.domain.NjtAgriculturalProductCertification;
import com.yaorange.nongjt.service.INjtAgriculturalProductCertificationService;
import com.yaorange.common.utils.poi.ExcelUtil;
import com.yaorange.common.core.page.TableDataInfo;

/**
 * 合格证打印列Controller
 * 
 * @author hzliu
 * @date 2025-09-27
 */
@RestController
@RequestMapping("/nongjt/certification")
public class NjtAgriculturalProductCertificationController extends BaseController
{
    @Autowired
    private INjtAgriculturalProductCertificationService njtAgriculturalProductCertificationService;

    /**
     * 查询合格证打印列列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certification:list')")
    @GetMapping("/list")
    public TableDataInfo list(NjtAgriculturalProductCertification njtAgriculturalProductCertification)
    {
        startPage();
        List<NjtAgriculturalProductCertification> list = njtAgriculturalProductCertificationService.selectNjtAgriculturalProductCertificationList(njtAgriculturalProductCertification);
        return getDataTable(list);
    }

    /**
     * 导出合格证打印列列表
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certification:export')")
    @Log(title = "合格证打印列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NjtAgriculturalProductCertification njtAgriculturalProductCertification)
    {
        List<NjtAgriculturalProductCertification> list = njtAgriculturalProductCertificationService.selectNjtAgriculturalProductCertificationList(njtAgriculturalProductCertification);
        ExcelUtil<NjtAgriculturalProductCertification> util = new ExcelUtil<NjtAgriculturalProductCertification>(NjtAgriculturalProductCertification.class);
        util.exportExcel(response, list, "合格证打印列数据");
    }

    /**
     * 获取合格证打印列详细信息
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certification:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(njtAgriculturalProductCertificationService.selectNjtAgriculturalProductCertificationById(id));
    }

    /**
     * 新增合格证打印列
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certification:add')")
    @Log(title = "合格证打印列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NjtAgriculturalProductCertification njtAgriculturalProductCertification)
    {
        return toAjax(njtAgriculturalProductCertificationService.insertNjtAgriculturalProductCertification(njtAgriculturalProductCertification));
    }

    /**
     * 修改合格证打印列
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certification:edit')")
    @Log(title = "合格证打印列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NjtAgriculturalProductCertification njtAgriculturalProductCertification)
    {
        return toAjax(njtAgriculturalProductCertificationService.updateNjtAgriculturalProductCertification(njtAgriculturalProductCertification));
    }

    /**
     * 删除合格证打印列
     */
    @PreAuthorize("@ss.hasPermi('nongjt:certification:remove')")
    @Log(title = "合格证打印列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(njtAgriculturalProductCertificationService.deleteNjtAgriculturalProductCertificationByIds(ids));
    }

    /**
     * 获取按ID分组的quantity统计数据，并包含产品名称
     */
    @GetMapping("/quantity/groupById")
    public AjaxResult getQuantityGroupById()
    {
        List<NjtAgriculturalProductCertification> list = njtAgriculturalProductCertificationService.getQuantityGroupById();
        System.out.println(list);
        return AjaxResult.success(list);
    }
}
